#include <vtkForceDirectedLayoutStrategy.h>
#include <vtkGraphLayoutView.h>
#include <vtkMutableUndirectedGraph.h>
#include <vtkNamedColors.h>
#include <vtkNew.h>
#include <vtkRenderWindow.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkRenderer.h>

#include <vtkArcSource.h>
#include <vtkPolyDataMapper.h>
#include "vtkPolygon.h"
#include "vtkRegularPolygonSource.h"
#include "vtkEllipseArcSource.h"
#include "vtkProperty.h"


int main(int, char*[])
{
    vtkNew<vtkRenderer> renderer;
    vtkNew<vtkRenderWindow> renderWindow;
    renderWindow->SetWindowName("RegularPolygonSource");
    renderWindow->AddRenderer(renderer);
    vtkNew<vtkRenderWindowInteractor> renderWindowInteractor;
    renderWindowInteractor->SetRenderWindow(renderWindow);


//    vtkClipPolyData


    vtkNew<vtkNamedColors> colors;


    vtkNew<vtkArcSource> arc;
    arc->SetCenter(0, 0, 0);
    arc->SetPoint1(2, 0, 0);
    arc->SetPoint2(0, 2, 0);
    arc->SetResolution(5);
    arc->Update();

//    vtkNew<vtkArcSource> arc2;
//    arc2->SetCenter(0, 0, 0);
//    arc2->SetPoint1(1, 0, 0);
//    arc2->SetPoint2(0, 1, 0);
//    arc2->SetResolution(5);
//    arc2->Update();
//
    vtkNew<vtkPolyDataMapper> arcMapper;
    arcMapper->SetInputConnection(arc->GetOutputPort());


    vtkNew<vtkEllipseArcSource> ellipse;
    ellipse->SetStartAngle(100);
    ellipse->SetSegmentAngle(300);
    ellipse->SetCenter(2, 2, 0);
    ellipse->SetMajorRadiusVector(2, 0, 0);
    ellipse->SetNormal(0, 1, 1);
    ellipse->SetClose(true);
    ellipse->Update();

    vtkNew<vtkPolyDataMapper> ellipseMapper;
    ellipseMapper->SetInputConnection(ellipse->GetOutputPort());



    // Create a circle
    vtkNew<vtkRegularPolygonSource> polygonSource;
    // Comment this line to generate a disk instead of a circle.
    polygonSource->GeneratePolygonOff(); // 是否填充
    polygonSource->SetNumberOfSides(50);
    polygonSource->SetRadius(1);
    polygonSource->SetCenter(4, 4, 0);

    vtkNew<vtkPolyDataMapper> polygonSourceMapper;
    polygonSourceMapper->SetInputConnection(polygonSource->GetOutputPort());


    vtkNew<vtkActor> actor1;
    actor1->SetMapper(arcMapper);
    actor1->GetProperty()->EdgeVisibilityOn();
    actor1->GetProperty()->SetSpecularColor(0, 0.5, 0.5);
    actor1->GetProperty()->SetAmbientColor(0, 0.5, 0.5);
    vtkNew<vtkProperty> back;
    back->SetColor(colors->GetColor3d("Tomato").GetData());
    actor1->SetBackfaceProperty(back);
    renderer->AddActor(actor1);

    vtkNew<vtkActor> actor2;
    actor2->SetMapper(ellipseMapper);
    actor2->GetProperty()->EdgeVisibilityOn();
    actor2->GetProperty()->SetLineWidth(5);
    actor2->GetProperty()->SetColor(0.5, 0, 0.5);
    actor2->GetProperty()->SetSpecularColor(0, 0.5, 0.5);
    actor2->GetProperty()->SetAmbientColor(0, 0.5, 0.5);
    vtkNew<vtkProperty> back2;
    back2->SetColor(colors->GetColor3d("Tomato").GetData());
    actor2->SetBackfaceProperty(back2);
    renderer->AddActor(actor2);

    vtkNew<vtkActor> actor3;
    actor3->SetMapper(polygonSourceMapper);

    actor3->GetProperty()->EdgeVisibilityOn();
    actor3->GetProperty()->SetSpecularColor(0, 0.5, 0.5);
    actor3->GetProperty()->SetAmbientColor(0, 0.5, 0.5);
    vtkNew<vtkProperty> back3;
    back3->SetColor(colors->GetColor3d("Tomato").GetData());
    actor3->SetBackfaceProperty(back3);
    renderer->AddActor(actor3);


//    // Setup four tubeFilter2
//    vtkNew<vtkPoints> tubeFilter2;
//    tubeFilter2->InsertNextPoint(0.0, 0.0, 0.0);
//    tubeFilter2->InsertNextPoint(1.0, 0.0, 0.0);
//    tubeFilter2->InsertNextPoint(1.0, 1.0, 0.0);
//    tubeFilter2->InsertNextPoint(0.0, 1.0, 0.0);
//
//    // Create the polygon
//    vtkNew<vtkPolygon> polygon;
//    polygon->GetPointIds()->SetNumberOfIds(4); // make a quad
//    polygon->GetPointIds()->SetId(0, 0);
//    polygon->GetPointIds()->SetId(1, 1);
//    polygon->GetPointIds()->SetId(2, 2);
//    polygon->GetPointIds()->SetId(3, 3);
//
//    // Add the polygon to a list of polygons
//    vtkNew<vtkCellArray> polygons;
//    polygons->InsertNextCell(polygon);
//
//    // Create a PolyData
//    vtkNew<vtkPolyData> polygonPolyData;
//    polygonPolyData->SetPoints(tubeFilter2);
//    polygonPolyData->SetPolys(polygons);
//
//    // Create a mapper and actor
//    vtkNew<vtkPolyDataMapper> mapper;
//    mapper->SetInputData(polygonPolyData);

//    vtkNew<vtkActor> actor;
//    actor->SetMapper(mapper);
//    actor->GetProperty()->EdgeVisibilityOn();

//    vtkColor3d actorColor = colors->GetColor3d("AliceBlue");
//    vtkColor3d EdgeColour = colors->GetColor3d("SteelBlue");
//
//    actor->GetProperty()->SetColor(actorColor.GetData());
//    actor->GetProperty()->SetEdgeColor(EdgeColour.GetData());




//    renderer->AddActor(actor);
    renderer->SetBackground(colors->GetColor3d("Red").GetData());

    renderWindow->Render();
    renderWindowInteractor->Start();

    return EXIT_SUCCESS;
}